package info.hexin.mvc.view.impl;

import info.hexin.mvc.view.ViewModel;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class JsonView implements ViewModel {

    private Object object;

    public JsonView(Object object) {
        this.object = object;
    }

    @Override
    public void render(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        PrintWriter out = response.getWriter();
        String json = JSON.toJSONString(object);
//        logger.debug("method result json  >>>>>>  {}", json);
        out.append(json);
        out.flush();
        out.close();
    }
}
